package com.cuit.bysj.InterfaceAction;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cuit.bysj.entities.Appraise;
import com.cuit.bysj.entities.User;
import com.cuit.bysj.service.AppraiseService;
import com.cuit.bysj.service.AppraiseTcherService;
import com.cuit.bysj.utils.SelectUtils;
import com.opensymphony.xwork2.ActionSupport;

//此接口用作学生查看自己的评价任务，已评价的内容
public class androidAppraiseTcher extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AppraiseTcherService appraisetcherService;
	private AppraiseService appraiseService;
	private String userid;
	private Map<String, Object> dataMap;
	private User user;
	private List<Appraise> list;
	private String id;
	private String score;
	private String content;
	private String selectArr;
	private String result;
	private String reply;

	public String getReply() {
		return reply;
	}

	public void setReply(String reply) {
		this.reply = reply;
	}

	public String getSelectArr() {
		return selectArr;
	}

	public void setSelectArr(String selectArr) {
		this.selectArr = selectArr;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getScore() {
		return score;
	}

	public void setScore(String score) {
		this.score = score;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getResult() {
		return result;
	}

	public List<Appraise> getList() {
		return list;
	}

	public void setappraiseService(AppraiseService appraiseService) {
		this.appraiseService = appraiseService;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setAppraisetcherService(AppraiseTcherService appraisetcherService) {
		this.appraisetcherService = appraisetcherService;
	}

	// 返回当前学生需要评价的教师列表方法
	public String querylistByid() throws IOException {
		user = appraisetcherService.findUser(Integer.parseInt(userid));
		list = appraisetcherService.loadlist(user.getStu());

		dataMap = new HashMap<String, Object>();
		dataMap.put("AppraiseList", list);
		dataMap.put("isOpen", appraisetcherService.isOpen());

		return "json";
	}

	// 返回已评价的列表方法
	@SuppressWarnings("unchecked")
	public String alreadyList() {
		user = appraisetcherService.findUser(Integer.parseInt(userid));
		list = appraiseService.queryListbyId(user);

		dataMap = new HashMap<String, Object>();
		dataMap.put("AppraiseList", list);

		return "json";
	}

	@SuppressWarnings("rawtypes")
	public String ItemList() {
		List list = appraisetcherService.initItem();

		dataMap = new HashMap<String, Object>();
		dataMap.put("ItemList", list);

		return "json";
	}

	public String saveAppraise() {
		String str = SelectUtils.saveSelect(selectArr, appraisetcherService.initItem());
		double sum = SelectUtils.caculateScore(selectArr, appraisetcherService.initItem());

		appraisetcherService.saveform(id, content, String.valueOf(sum), str);

		dataMap = new HashMap<String, Object>();
		dataMap.put("code", "success");

		return "json";
	}

	public String replyAppraise() {
		Appraise appraise = appraisetcherService.findAppraiseTable(Integer.parseInt(id));
		appraise.setReply(reply);

		appraiseService.updateAppraise(appraise);

		dataMap = new HashMap<String, Object>();
		dataMap.put("code", "回复成功!");

		return "json";
	}

	public String AdminseeList() {
		dataMap = new HashMap<String, Object>();
		dataMap.put("adminseeList", appraiseService.initAdminSeeList());

		return "json";
	}

	
	public String tcherTable() {
		dataMap = new HashMap<String, Object>();
		dataMap.put("Tchertable", appraiseService.findListbyTcherId(id, content, result));

		return "json";
	}

	// 返回教师查看的班级列表，一级菜单
	public String TcherSeeList() {
		dataMap = new HashMap<String, Object>();
		dataMap.put("tcherseeList", appraiseService.initTcherSeelist(id));

		return "json";
	}

	// major, banji, cname
	public String TcherClassList() {
		dataMap = new HashMap<String, Object>();
		System.out.println(score+content+result);
		dataMap.put("TcherClassList", appraiseService.queryListbyInfo(score, content, result));

		return "json";
	}

	public void setResult(String result) {
		this.result = result;
	}
}
